import { defineStore } from 'pinia';
import { MeasureTool, MeasureType } from '@/utils/measure/MeasureTool';
import { SuperMap3D } from '@/utils/supermap3d';

export const useMeasureStore = defineStore('measure', {
  state: () => ({
    measureTool: null as MeasureTool | null,
    activeType: null as MeasureType | null,
    isMeasuring: false,
  }),
  actions: {
    initMeasureTool(viewer: any) {
      if (!this.measureTool) {
        this.measureTool = new MeasureTool(viewer);
      }
    },
    startMeasure(type: MeasureType) {
      if (!this.measureTool) return;
      this.measureTool.startMeasure(type);
      this.activeType = type;
      this.isMeasuring = true;
    },
    clearMeasure() {
      this.measureTool?.clear();
      this.activeType = null;
      this.isMeasuring = false;
    },
    // destroyMeasure() {
    //   this.measureTool?.destroy();
    //   this.measureTool = null;
    //   this.activeType = null;
    //   this.isMeasuring = false;
    // },
  },
});
